package tt.dz.service.imp.base;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tt.dz.dao.base.BaseDao;
import tt.dz.entity.station.OmsStationLocation;
import tt.dz.service.base.OmsStationLocationService;
@Service @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class OmsStationLocationServiceImpl extends BaseService implements OmsStationLocationService{
	@Autowired
	@Qualifier("base")
	private BaseDao<OmsStationLocation> baseDao;
	
	private Log log = LogFactory.getLog(this.getClass());	
	
	@Override
	public List<OmsStationLocation> findByStationId(String id) {
		try 
		{
			OmsStationLocation queryLocation = new OmsStationLocation();
			queryLocation.setStation_id(id);
//			queryLocation.setValid_flag(1);
			List<OmsStationLocation> lsStationLoc = baseDao.findExample(queryLocation, null, null, null, 1);
			return lsStationLoc;
		} 
		catch (Exception e) 
		{
			log.error(e.getMessage(), e);
			throw e;
		}
	}
	
	
	@Override
	public List<OmsStationLocation> findAll() 
	{
		try 
		{
			OmsStationLocation location = new OmsStationLocation();
			List<OmsStationLocation> lst= this.baseDao.findAll(location);
			return lst;
		} catch (Exception e) {
			this.logError(e.getMessage(), e);
			return null;
		}
	}


	@Override
	public int save(OmsStationLocation obj) {
		int result = this.baseDao.save(obj);
		return result;
	}


	@Override
	public int update(OmsStationLocation obj) {
		int result = this.baseDao.updateObject(obj);
		return result;
	}


	@Override
	public List<OmsStationLocation> findValidByStationId(String stationId) {
		try 
		{
			OmsStationLocation queryLocation = new OmsStationLocation();
			queryLocation.setStation_id(stationId);
			queryLocation.setValid_flag(1);
			List<OmsStationLocation> lsStationLoc = baseDao.findExample(queryLocation, null, null, null, 1);
			return lsStationLoc;
		} 
		catch (Exception e) 
		{
			log.error(e.getMessage(), e);
			throw e;
		}
	}
	
}
